package com.originskyseed.platform.user.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.sun.org.apache.regexp.internal.RE;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.mapper.LevelSystemRelDeptMapper;
import com.originskyseed.platform.user.model.LevelSystemRelDept;
import com.originskyseed.platform.user.service.ILevelSystemRelDeptService;

/**
 * 等级体系关联公司信息Service接口实现类（OSI_LEVEL_SYSTEM_REL_DEPT）
 * 
 * @author Tangwanghui
 */
@DubboService
@Component("levelSystemRelDeptService")
public class LevelSystemRelDeptServiceImpl implements ILevelSystemRelDeptService {

	@Resource
	private LevelSystemRelDeptMapper levelSystemRelDeptMapper;

	/**
	 * 删除记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.levelSystemRelDeptMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 删除记录,通过部门id
	 *
	 * @param deptId
	 * @return
	 * @throws Exception
	 */
	public int deleteByDeptId(String deptId) throws Exception{
		return this.levelSystemRelDeptMapper.deleteByDeptId(deptId);
	}

	/**
	 * 批量删除记录
	 * 
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.levelSystemRelDeptMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(LevelSystemRelDept record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.levelSystemRelDeptMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(LevelSystemRelDept record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.levelSystemRelDeptMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(LevelSystemRelDept record) throws Exception {
		record.setUpdateTime(new Date());
		return this.levelSystemRelDeptMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(LevelSystemRelDept record) throws Exception {
		record.setUpdateTime(new Date());
		return this.levelSystemRelDeptMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public LevelSystemRelDept selectByPrimaryKey(String id) throws Exception {
		return this.levelSystemRelDeptMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<LevelSystemRelDept> selectList(LevelSystemRelDept record) throws Exception {
		return this.levelSystemRelDeptMapper.selectList(record);
	}

	/**
	 * 查询等级体系id是否存在
	 *
	 * @param levelSystemId
	 * @return
	 * @throws Exception
	 */
	public String selectExistLevelSystem(String levelSystemId) throws Exception{
		return this.levelSystemRelDeptMapper.selectExistLevelSystem(levelSystemId);
	}

	/**
	 * 查询等级体系id,通过部门id查询
	 *
	 * @param deptId
	 * @return
	 * @throws Exception
	 */
	public String selectLevelSystemIdByDeptId(String deptId) throws Exception{
		return this.levelSystemRelDeptMapper.selectLevelSystemIdByDeptId(deptId);
	}


	/**
	 * 分页查询列表
	 * 
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<LevelSystemRelDept> selectListByPage(Map<String, Object> params, BasePage<LevelSystemRelDept> page) throws Exception {
		params.put("page", page);
		List<LevelSystemRelDept> list = this.levelSystemRelDeptMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

}